package com.briup.jz.service.impl;

import com.briup.jz.bean.AccountEmployee;
import com.briup.jz.bean.AccountEmployeeExample;
import com.briup.jz.dao.AccountEmployeeMapper;
import com.briup.jz.service.AccountEmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class AccountEmployeeServiceImpl implements AccountEmployeeService {

  @Autowired private AccountEmployeeMapper accountEmployeeMapper;

  @Override
  public void saveOrUpdate(AccountEmployee accountemployee) {
    if (accountemployee.getId() != null) {
      accountemployee.setTransferTime(new Date().getTime());
      accountEmployeeMapper.updateByPrimaryKey(accountemployee);
    } else {
      accountemployee.setTransferTime(new Date().getTime());
      accountEmployeeMapper.insert(accountemployee);
    }
  }

  @Override
  public void deleteById(long id) {
    accountEmployeeMapper.deleteByPrimaryKey(id);
  }

  @Override
  public AccountEmployee queryAccountEmployeeById(long id) {

    return accountEmployeeMapper.selectByPrimaryKey(id);
  }

  @Override
  public List<AccountEmployee> query(String type, String status, Long userId) {
    AccountEmployeeExample example = new AccountEmployeeExample();
    AccountEmployeeExample.Criteria criteria = example.createCriteria();
    if (type != null) {
      criteria.andTypeEqualTo(type);
    }
    if (status != null) {
      criteria.andStatusEqualTo(status);
    }
    if (userId != null) {
      criteria.andUserIdEqualTo(userId);
    }

    List<AccountEmployee> list = accountEmployeeMapper.selectByExample(example);
    return list;
  }
}
